package com.eascs.caseManagement.controller;


import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.app.dao.PageResult;
import com.eascs.caseManagement.entity.CaseManagement;
import com.eascs.caseManagement.form.CaseManageForm;
import com.eascs.caseManagement.service.CaseManageService;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;


@Controller
@RequestMapping("/caseManage")
public class CaseManageController extends BaseMasterViewController {
	
	
	@Inject
	CaseManageService caseManageService;
	
	
	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "caseManage");
	}

	@RequestMapping(value = "/list")
	public String caseManageList(CaseManageForm vo) {
		vo.setPageSize(10);
		PageResult<Object[]> pageResult = caseManageService.caseManageList(vo);
		String[] titles = {"编号","案号","贷款单号","借款人","诉讼金额（元）","一审立案金额","案件已收回金额（元）","放款日期","到期日","更新时间","更新人"};
		Button detailButton = ButtonHelper.createOpenButton("详情", "/caseManage/detail?id=");
		Button delete = ButtonHelper.createAjaxConfirmButton("删除", "/caseManageRest/delete?id=");
		//Button edit = ButtonHelper.createAjaxButton("编辑", "/caseManageRest/edit?id=");
		Button[] morButtons = new Button[] { detailButton,delete};
		String findCondition = "";
		String pageUrl = "/caseManage/list";

		if (vo != null) {
			String loanId = vo.getLoanId() == null ? "" : vo.getLoanId();
			String referNum = vo.getReferNum() == null ? "" : vo.getReferNum();
			String num = vo.getNum() == null ? "" : vo.getNum();
			String operator = vo.getOperator() == null ? "" : vo.getOperator();
			findCondition = "loanId?=" + loanId + "&referNum=" + referNum + "&num=" + num + "&operator=" + operator;
			pageUrl = pageUrl + findCondition;
		}
		
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl + "&pageIndex=");
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(morButtons);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		return "/caseManage/index";

	}
	
	@RequestMapping(value = "/detail")
	public String showCustomerDetailInfo(String id) {
		CaseManagement cm = caseManageService.getCaseManageById(id);
		ViewContext.put("vo", cm);
		BaseRestResult.refresh();
		return "/caseManage/detail";
	}
}
